<!DOCTYPE html>
<html>

<head>
    <meta charset="UTF-8">
    <title>实现全选全不选案例 - 表格</title>
    <style>
        * {
            padding: 0;
            margin: 0;
        }

        .wrap {
            width: 300px;
            margin: 100px auto 0;
        }

        table {
            border-collapse: collapse;
            border-spacing: 0;
            border: 1px solid #c0c0c0;
        }

        th,
        td {
            border: 1px solid #d0d0d0;
            color: #404060;
            padding: 10px;
        }

        th {
            background-color: #09c;
            font: bold 16px "微软雅黑";
            color: #fff;
        }

        td {
            font: 14px "微软雅黑";
        }

        tbody tr {
            background-color: #f0f0f0;
        }

        tbody tr:hover {
            cursor: pointer;
            background-color: #fafafa;
        }
    </style>
</head>

<body>
    <div class="wrap">
        <table>
            <thead>
                <tr>
                    <th>
                        <input type="checkbox" id="j_cbAll" />
                    </th>
                    <th>课程名称</th>
                    <th>所属学院</th>
                </tr>
            </thead>
            <tbody id="j_tb">
                <tr>
                    <td>
                        <input type="checkbox" />
                    </td>
                    <td>JavaScript</td>
                    <td>计算机学院</td>
                </tr>
                <tr>
                    <td>
                        <input type="checkbox" />
                    </td>
                    <td>css</td>
                    <td>计算机学院</td>
                </tr>
                <tr>
                    <td>
                        <input type="checkbox" />
                    </td>
                    <td>html</td>
                    <td>计算机学院</td>
                </tr>
                <tr>
                    <td>
                        <input type="checkbox" />
                    </td>
                    <td>jQuery</td>
                    <td>计算机学院</td>
                </tr>
            </tbody>
        </table>
    </div>
</body>
<script src="https://cdn.staticfile.org/jquery/1.10.2/jquery.min.js"></script>
<script>
    $(function () {
        let $c = $('#j_tb input')
        $('#j_cbAll').click(function () {
            $c.prop('checked', $(this).prop('checked'))
        })
        $c.click(function () {
            let $cd = $('#j_tb :checked');
            // console.log($cd.length, $c.length);
            if ($cd.length == $c.length) {
                $('#j_cbAll').prop('checked', true)
            } else {
                $('#j_cbAll').prop('checked', false)

            }
        })
    })
</script>

</html>